package ua.mk.chdu.rtem.diploma.core.agents.scheduling.behaviours;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import ua.mk.chdu.rtem.diploma.core.agents.scheduling.TaskSchedulingAgent;
import ua.mk.chdu.rtem.diploma.core.model.enums.MessageTypes;
import ua.mk.chdu.rtem.diploma.core.model.global.AgentList;

public class SendingPerformanceRequestBehaviour extends OneShotBehaviour {
    private TaskSchedulingAgent agent;

    public SendingPerformanceRequestBehaviour(TaskSchedulingAgent agent) {
        super(agent);
        this.agent = agent;
    }

    @Override
    public void action() {
        System.out.println("SENDING PERFORMANCE REQUEST BEHAVIOUR ACTIVATED");
        ACLMessage performanceReportRequest = buildPerformanceRequestMessage();
        agent.send(performanceReportRequest);
        agent.removeBehaviour(this);
    }

    private ACLMessage buildPerformanceRequestMessage() {
        ACLMessage aclMessage = new ACLMessage(ACLMessage.REQUEST);
        aclMessage.setReplyWith(MessageTypes.GET_PERFORMANCE_REPORT.getValue());
        aclMessage.addReceiver(new AID(AgentList.getInstance().getPerformanceAgent(), AID.ISLOCALNAME));
        return aclMessage;
    }
}
